Creating an event handler

What should be done, if it is necessary to define a new event handler, which does not belong to the basic class? Let us examine it on the example of the “TfrxEditControl” common control:

TfrxEditControl = class (TfrxDialogControl)

private

FEdit: TEdit;

{ new event }

FOnChange: TfrxNotifyEvent;

procedure DoOnChange(Sender: TObject);

...

public

constructor Create(AOwner: TComponent); override ;

...

published

{ new event }

property OnChange: TfrxNotifyEvent read FOnChange write FOnChange;

...

end;

constructor TfrxEditControl.Create(AOwner: TComponent);

begin

...

{ connect our handler }

FEdit.OnChange := DoOnChange;

InitControl(FEdit);

...

end;

procedure TfrxEditControl.DoOnChange(Sender: TObject);

begin

{ call event's handler }

if Report <> nil then

Report.DoNotifyEvent(Sender, FOnChange);

end;

It is important to notice that events in FastReport are a procedure declared in the report's script. A string containing its name will be the link to such handler. That is why, for example, unlike the Delphi TNotifyEvent type, which is the method's address, the handler's type in FastReport is a string (the TfrxNotifyEvent type is declared as String [63]).